{include file='header'/}
<title>修改密码</title>
<style>
    .layui-form-item .layui-input-company {
        width: auto;
        padding-right: 10px;
        line-height: 38px;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-verify="required" lay-reqtext="旧的密码不能为空"
                           placeholder="请输入旧的密码" value="" class="layui-input">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-verify="required|pwd" lay-reqtext="新的密码不能为空"
                           placeholder="请输入新的密码" value="" class="layui-input">
                    <tip>新密码6-15位且不能出现空格。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-verify="required|confirmPass"
                           lay-reqtext="确认密码不能为空" placeholder="请输入确认密码" value="" class="layui-input">
                    <tip>确认密码要和新密码相同。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file='footer'/}
<script>
  layui.use(['form', 'miniTab', ['jquery']], function () {
    var form = layui.form, $ = layui.jquery, layer = layui.layer, miniTab = layui.miniTab;
    form.verify({
      pwd: [
        /^[\S]{6,15}$/
        , '密码必须6到15位，且不能出现空格'
      ],
      confirmPass: function (value) {
        if ($('input[name=new_password]').val() !== value)
          return '两次密码输入不一致！';
      }
    });
    //监听提交
    form.on('submit(saveBtn)', function (data) {
      $.post("{:__url('index/editPassword')}", data.field, function (res) {
        if (res.code == 1) {
          layer.msg(res.msg, {icon: 1}, function () {
            window.location.reload();
          });
        } else {
          layer.msg(res.msg, {icon: 2}, function () {
            window.location.reload();
          });
        }
      })
    });

  });
</script>
</body>
</html>